<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   <input type="text">
    <script>
        // 1、输出结果
     var a = 10;
(function () {
    console.log(a)//undefined 因为下面声明var a变量提升了，所以为undefined，在自执行函数形成的独立作用域
   var a = 5
    console.log(window.a)//10
    // let a = 20;//如果是let声明则会报错 Cannot access 'a' before initialization
    console.log(a)//20
})()


// 2、
var a = 10;
(function () {
    console.log(a)//10 如果里面没有声明a则向上层作用域查找
    a = 5
    console.log(window.a)//5
    console.log(a)//5
})()



    </script>
</body>
</html>